% This is the file CJKfntef.sty of the CJK package
%   extending CJKulem.sty with more font effects
%
% created by Wenchang Sun <sunwch@hotmail.com>
%            Werner Lemberg <wl@gnu.org>
%
% Version 4.8.1 (10-Aug-2008)
%
% Macros:
%   \CJKunderdot{...}
%   \CJKunderline[*]{...}
%   \CJKunderdblline[*]{...}
%   \CJKunderwave[*]{...}
%   \CJKsout[*]{...}
%   \CJKxout[*]{...}
%
%   The following nesting combinations are allowed:
%
%     \CJKunderdot{...\CJKunderline[*]{...}...}
%     \CJKunderdot{...\CJKunderdblline[*]{...}...}
%     \CJKunderdot{...\CJKunderwave[*]{...}...}
%     \CJKunderdot{...\CJKsout[*]{...}...}
%     \CJKunderdot{...\CJKxout[*]{...}...}
%
%     \CJKunderline[*]{...\CJKunderdot{...}...}
%     \CJKunderdblline[*]{...\CJKunderdot{...}...}
%     \CJKunderwave[*]{...\CJKunderdot{...}...}
%     \CJKsout[*]{...\CJKunderdot{...}...}
%     \CJKxout[*]{...\CJKunderdot{...}...}
%
% Environment:
%   CJKfilltwosides

% Copyright (C) 1994-2008  Werner Lemberg <wl@gnu.org>
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program in doc/COPYING; if not, write to the Free
% Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
% MA 02110-1301 USA

\NeedsTeXFormat{LaTeX2e}[1998/06/01]
\def\fileversion{4.8.1}
\def\filedate{2008/08/10}
\ProvidesPackage{CJKfntef}[\filedate\space\fileversion]

\RequirePackage{CJK}
\RequirePackage{CJKulem}


\endlinechar \m@ne

\ifx\CJKpunctsymbol\undefined
  \PackageWarning{CJKfntef}{
    You need to download the last version of the CJK package\MessageBreak
    to keep CJK punctuation from being underdotted}
  \let\CJKpunctsymbol\CJKsymbol
\fi


\newskip\CJK@fntefSkip
\newcount\CJK@nest
\newdimen\CJK@fntefDimen
\newbox\CJK@underdotBox
\newbox\CJK@ULbox

\newif\ifCJK@UL@
\CJK@UL@false
\newif\ifCJK@sxout@
\CJK@sxout@false


\newcommand{\CJKunderdotbasesep}{0.05em}
\newcommand{\CJKunderdotsep}{0.04em}
\newcommand{\CJKunderlinebasesep}{0.20em}
\newcommand{\CJKunderlinesep}{0.07em}
\newcommand{\CJKunderdbllinebasesep}{0.20em}
\newcommand{\CJKunderdbllinesep}{0.17em}
\newcommand{\CJKunderwavebasesep}{0.20em}
\newcommand{\CJKunderwavesep}{0.00em}
\newcommand{\CJKsoutheight}{0.35em}


\ifx\color\undefined
  \def\CJKunderdotcolor{}
  \def\CJKunderwavecolor{}
  \def\CJKunderlinecolor{}
  \def\CJKunderdbllinecolor{}
  \def\CJKsoutcolor{}
  \def\CJKxoutcolor{}
\else
  \def\CJKunderdotcolor{\color{red}}
  \def\CJKunderwavecolor{\color{blue}}
  \def\CJKunderlinecolor{\color{blue}}
  \def\CJKunderdbllinecolor{\color{blue}}
  \def\CJKsoutcolor{\color{red}}
  \def\CJKxoutcolor{\color{blue}}
\fi


%
% \CJKunderdot:
%   Add a dot under every CJK non-punctuation character.  The dot position
%   can be controlled by redefining \CJKunderdotsep (for nesting) and
%   \CJKunderdotbasesep.
%
%   The dot color can be changed by redefining \CJKunderdotcolor.
%
\def\CJK@underdotSkip{\z@}

\def\CJK@preUnderdot{
  \ifnum\CJK@nest = \z@
    \global\advance\CJK@fntefSkip \CJKunderdotbasesep
  \fi
  \global\advance\CJK@nest \@ne

  \xdef\CJK@underdotSkip{\the\CJK@fntefSkip}
  \global\advance\CJK@fntefSkip \CJKunderdotsep

  \global\setbox\CJK@underdotBox\hbox{{
    \CJKunderdotcolor
    {$\cdot$}}}
  \global\advance\CJK@fntefSkip \ht\CJK@underdotBox
  \global\advance\CJK@fntefSkip \dp\CJK@underdotBox}

\def\CJK@postUnderdot{
  \global\advance\CJK@fntefSkip -\CJKunderdotsep
  \global\advance\CJK@fntefSkip -\ht\CJK@underdotBox
  \global\advance\CJK@fntefSkip -\dp\CJK@underdotBox
  \gdef\CJK@underdotSkip{\z@}

  \global\advance\CJK@nest \m@ne
  \ifnum\CJK@nest = \z@
    \global\advance\CJK@fntefSkip -\CJKunderdotbasesep
  \fi}

\newcommand{\CJKunderdot}[1]{
  \CJK@preUnderdot

  \global\let\CJK@underdotSymbol \CJKsymbol
  \gdef\CJKsymbol##1{
    \CJK@underdotSymbol{##1}
    \settowidth\CJK@fntefDimen{\CJK@underdotSymbol{##1}}

    \leavevmode
    \rlap{
      \vbox to \z@ {
        \vskip\CJK@underdotSkip
        \hbox to \z@ {
          \hskip -\CJK@fntefDimen
          \hss
          \copy\CJK@underdotBox
          \hss}
        \hskip -\CJK@fntefDimen
        \vss}}}
  #1
  \global\let\CJKsymbol \CJK@underdotSymbol

  \CJK@postUnderdot
  \ignorespaces}


%
% Auxiliary macros needed by \CJKunderline and friends.
%
\def\UL@CJKpunctnobreakglue{
  \ifx\ \LA@space
    \LA@CJKglue
  \else
    \egroup
    \UL@stop
    \UL@start
    \bgroup
  \fi}

\def\CJK@fntefSave{
  \global\let\UL@UL@CJKnobreakglue \UL@CJKnobreakglue
  \global\let\UL@CJKsymbol \CJKsymbol
  \global\let\UL@CJKpunctsymbol \CJKpunctsymbol}

\def\CJK@fntefRestore{
  \global\let\UL@CJKnobreakglue \UL@UL@CJKnobreakglue
  \global\let\CJKsymbol \UL@CJKsymbol
  \global\let\CJKpunctsymbol \UL@CJKpunctsymbol}

\def\CJK@preUL{
  \ifCJK@UL@
    \PackageError{CJKfntef}
      {Nesting error}
      {Nesting \string\CJKunderwave[*], \string\CJKunderline[*],
       \string\CJKsout[*], \string\CJKxout[*],\MessageBreak
       or \string\CJKunderdblline[*] is not supported.}
  \else
    \global\CJK@UL@true
  \fi
  \ifCJK@sxout@
    \gdef\CJK@ULskip{\z@}
  \else
    \ifnum\CJK@nest = \z@
      \global\advance\CJK@fntefSkip \CJK@ULbasesep
    \fi
    \global\advance\CJK@nest \@ne

    \global\advance\CJK@fntefSkip \ht\CJK@ULbox
    \global\advance\CJK@fntefSkip \dp\CJK@ULbox

    \xdef\CJK@ULskip{\the\CJK@fntefSkip}
    \global\advance\CJK@fntefSkip \CJK@ULsep
  \fi}

\def\CJK@postUL{
  \global\CJK@UL@false

  \ifCJK@sxout@
    \global\CJK@sxout@false
  \else
    \global\advance\CJK@fntefSkip -\CJK@ULsep
    \global\advance\CJK@fntefSkip -\ht\CJK@ULbox
    \global\advance\CJK@fntefSkip -\dp\CJK@ULbox

    \global\advance\CJK@nest \m@ne
    \ifnum\CJK@nest = \z@
      \global\advance\CJK@fntefSkip -\CJK@ULbasesep
    \fi
  \fi}

\def\CJK@UL{
  \CJK@preUL
  \CJK@fntefSave

  \global\let\UL@CJKnobreakglue \UL@CJKpunctnobreakglue
  \gdef\CJKsymbol{
    \gdef\UL@leadtype{\leaders\copy\ULC@box}
    \UL@CJKsymbol}
  \gdef\CJKpunctsymbol{
    \gdef\UL@leadtype{}
    \UL@CJKpunctsymbol}

  \bgroup
    \markoverwith{
      \lower\CJK@ULskip\copy\CJK@ULbox}
    \aftergroup\CJK@fntefRestore
    \aftergroup\CJK@postUL
    \ULon}

\def\CJK@@UL{
  \CJK@preUL
  \bgroup
    \markoverwith{
      \lower\CJK@ULskip\copy\CJK@ULbox}
    \aftergroup\CJK@postUL
    \ULon}


%
% \CJKunderwave*:
%   The same as \uwave except that the wavy line is colored (you can change
%   the color by redefining \CJKunderwavecolor), and the position can be
%   controlled by redefining \CJKunderwavesep (for nesting) and
%   \CJKunderwavebasesep.
%
% \CJKunderwave:
%   The same as \CJKunderwave* but ignoring CJK punctuation characters.
%
\newcommand{\CJKunderwave}{
  \global\let\CJK@ULsep \CJKunderwavesep
  \global\let\CJK@ULbasesep \CJKunderwavebasesep
  \global\setbox\CJK@ULbox\hbox{{
    \CJKunderwavecolor
    \sixly
    \char 58}}

  \@ifstar\CJK@@UL\CJK@UL}


%
% \CJKunderline*:
%   The same as \uline except that the line is colored (you can change the
%   color by redefining \CJKunderlinecolor), and the position can be
%   controlled by redefining \CJKunderlinesep (for nesting) and
%   \CJKunderlinebasesep.
%
% \CJKunderline:
%   The same as \CJKunderline* but ignoring CJK punctuation characters.
%
\newcommand{\CJKunderline}{
  \global\let\CJK@ULsep \CJKunderlinesep
  \global\let\CJK@ULbasesep \CJKunderlinebasesep
  \global\setbox\CJK@ULbox\hbox{{
    \CJKunderlinecolor
    \vtop{\hrule \@height \ULthickness \@width .2em}}}

  \@ifstar\CJK@@UL\CJK@UL}


%
% \CJKunderdblline[*]:
%   The same as \CJKunderline[*] except that two lines are used for
%   underlining.
%
\newcommand{\CJKunderdblline}{
  \global\let\CJK@ULsep \CJKunderdbllinesep
  \global\let\CJK@ULbasesep \CJKunderdbllinebasesep

  \global\setbox\CJK@ULbox\hbox{{
    \CJKunderdbllinecolor
    \vtop{
      \kern -.07em
      \hrule \@height\ULthickness \@width .2em
      \kern 1.1\p@
      \hrule}}}

  \@ifstar\CJK@@UL\CJK@UL}


%
% \CJKsout*:
%   The same as \sout except that the line is colored (you can change the
%   color by redefining \CJKsoutcolor), and the position can be controlled
%   by redefining \CJKsoutheight.
%
% \CJKsout:
%   The same as \CJKsout* but ignoring CJK punctuation characters.
%
\def\CJKsout{
  \global\CJK@sxout@true
  \global\setbox\CJK@ULbox\hbox{{
    \CJKsoutcolor
    \vtop{
      \kern -\CJKsoutheight
      \hrule \@height\ULthickness \@width .2em}}}

  \@ifstar\CJK@@UL\CJK@UL}


%
% \CJKxout*:
%   The same as \xout except using colored `/' (you can change the color
%   by redefining \CJKxoutcolor).
%
% \CJKxout:
%   The same as \CJKxout* but ignoring CJK punctuation characters.
%
\def\CJKxout{
  \global\CJK@sxout@true
  \global\setbox\CJK@ULbox\hbox{{
    \kern -0.1em
    {\CJKxoutcolor $/$}
    \kern -0.1em}}

  \@ifstar\CJK@@UL\CJK@UL}


%
%  CJKfilltwosides environment:
%    Align CJK characters to fill two sides.
%
%  Usage:
%    \begin{CJKfilltwosides}{width}
%      first line \\
%      second line \\
%      ... \\
%      last line
%    \end{CJKfilltwosides}
%
\newif\ifCJK@fillbegin@
\global\CJK@fillbegin@false
\newif\ifCJK@filltwosides@
\global\CJK@filltwosides@false

\newenvironment{CJKfilltwosides}[1]{
  \leavevmode
  \vbox\bgroup
    \global\CJK@filltwosides@true
    \global\let\CJK@filltwosidesSymbol \CJKsymbol

    \def\CJK@ftscr{
      \egroup
      \global\CJK@fillbegin@false
      \hbox to #1\bgroup
        \ignorespaces}

    \let\\ \CJK@ftscr

    \def\CJKsymbol##1{
      \ifCJK@fillbegin@
        \hfill
        \CJK@filltwosidesSymbol{##1}
      \else
        \CJK@filltwosidesSymbol{##1}
        \global\CJK@fillbegin@true
      \fi}

    \hbox to #1\bgroup
      \ignorespaces
 }{
  \egroup
  \egroup

  \global\let\CJKsymbol \CJK@filltwosidesSymbol
  \global\CJK@fillbegin@false
  \global\CJK@filltwosides@false}


\endlinechar `\^^M

\endinput
